package com.tim.source.db;

import java.io.InputStream;
import java.sql.Connection;
import java.sql.DriverManager;
import java.util.Properties;

public class ConnectionManager {
	private static Connection conn;

	public static Connection getConnection() {
		if (conn == null) {
			try {
				InputStream input = ConnectionManager.class
						.getResourceAsStream("jdbc.properties");
				Properties pp = new Properties();
				// 加载资源文件
				pp.load(input);
				// 获取数据库连接字符串
				Class.forName(pp.getProperty("dbDriver"));
				// 获取数据库Url
				String url = pp.getProperty("url");
				String user = pp.getProperty("user");
				String pwd = pp.getProperty("pwd");
				return DriverManager.getConnection(url, user, pwd);
			} catch (Exception e) {
				e.printStackTrace();
			}
			return null;
		} else {
			return ConnectionManager.conn;
		}
	}
}
